"""
Created by 饼干 on 2019/11/4 15:58
"""
from app.view_models.book import BookViewModel

__author__ = '饼干'


class MyTrades:
    def __init__(self, trade_of_mine, trade_count_list):
        self.trades = []
        self.__trade_of_mine = trade_of_mine
        self.__trade_count_list = trade_count_list
        self.trades = self.__parse()

    def __parse(self):
        temp_trades = []
        for trade in self.__trade_of_mine:
            my_trade = self.__matching(trade)
            temp_trades.append(my_trade)
        return temp_trades

    def __matching(self, trade):
        count = 0
        for trade_count in self.__trade_count_list:
            if trade.isbn == trade_count['isbn']:
                count = trade_count['count']
        r = {
            'wishes_count': count,
            'book': BookViewModel(trade.book),
            'id': trade.id
        }
        return r
